/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ASAInst;

import ASAExpr.ASAExpr;
import exception.DivisionByZeroException;
import exception.VariableNonDeclareeException;

/**
 *
 * @author FM & KB
 */
public class ASAInstTantQue extends ASAInst {

    private ASAExpr test;
    private ASAInst instructions;
    
    public ASAInstTantQue(ASAExpr test,ASAInst instructions){
        this.test = test;
        this.instructions = instructions;
    }
    
    @Override
    public void executer()throws VariableNonDeclareeException, DivisionByZeroException {
        while(this.test.evalue() != 0){
            this.instructions.executer();
        }
    }

    @Override
    public String notationExplorateur(String prefixe) {
        String res = prefixe + getLabelExplorateur() + "\n";
        String prefixeSuiv = prefixe + "   ";

        if (test != null) {
            res += test.notationExplorateur(prefixeSuiv);
            if(this.instructions != null){
                res += this.instructions.notationExplorateur(prefixeSuiv);
            }
        } else {
            res += prefixeSuiv + "VIDE\n";
        }
        return res;
    }

    @Override
    public String getLabelExplorateur() {
        return "WHILE";
    }    
}
